package com.dianrui.operation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dianrui.operation.R;
import com.dianrui.operation.bean.BoxStatus;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BoxListAdapter extends BaseAdapter {
    Context context;
    List<BoxStatus> list;
    BoxClickListener batteryClickListener;

    public BoxListAdapter(Context context, List<BoxStatus> list) {
        this.context = context;
        this.list = list;
    }

    public void refresh(List<BoxStatus> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public interface BoxClickListener {
        void onBoxClick(String msg_id);

    }

    public void setOnBoxClickListener(BoxClickListener messageClickListener) {
        this.batteryClickListener = messageClickListener;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_box_list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (list.size() > 0) {
            BoxStatus boxStatus = list.get(position);


        }
        return convertView;
    }


     class ViewHolder {
        @BindView(R.id.car_numbers)
        TextView carNumbers;
        @BindView(R.id.voltage)
        TextView voltage;
        @BindView(R.id.acc)
        TextView acc;
        @BindView(R.id.fortify)
        TextView fortify;
        @BindView(R.id.motor_lock)
        TextView motorLock;
        @BindView(R.id.battery_lock)
        TextView batteryLock;
        @BindView(R.id.low_voltage)
        TextView lowVoltage;
        @BindView(R.id.battery)
        TextView battery;
        @BindView(R.id.journey)
        TextView journey;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
